@import com.example.auction.pagination.PaginatedSequence

@(pagination: PaginatedSequence[_])(route: (Int, String) => Html )

@paginationItem(pageNumber: Int, label: String, isLinked: Boolean, disabledClass: String, otherClasses: String = "") = {
@defining(otherClasses + (if(!isLinked) " " + disabledClass else "")) { liClasses =>
    <li class="@liClasses">
    @if(isLinked) {
        @route(pageNumber , label)
    } else {
        @label
    }
    </li>
}
}

@prevPage() = @{
    pagination.getPage - 1
}
@nextPage() = @{
    pagination.getPage + 1
}

@if(pagination.isPaged) {
    <nav>
        <ul class="pagination" aria-label="Pagination">
            @paginationItem(
                prevPage(),
                Messages("pagination.prev"),
                isLinked = !pagination.isFirst,
                disabledClass = "disabled",
                otherClasses = "pagination-previous"
            )
            @for(pageNumber <- 0 until pagination.getPageCount) {
                @paginationItem(
                    pageNumber,
                    (pageNumber + 1).toString,
                    isLinked = pageNumber != pagination.getPage,
                    disabledClass = "current"
                )
            }
            @paginationItem(
                nextPage(),
                Messages("pagination.next"),
                isLinked = !pagination.isLast,
                disabledClass = "disabled",
                otherClasses = "pagination-next"
            )
        </ul>
    </nav>
}
